package com.ruoyi.storeIndex.service.impl;

import com.ruoyi.statistics.domain.OrderChange;
import com.ruoyi.storeIndex.domain.StoreOrder;
import com.ruoyi.storeIndex.mapper.StoreOrderStatisticsMapper;
import com.ruoyi.storeIndex.service.IStoreOrderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class StoreOrderStatisticsServiceImpl implements IStoreOrderStatisticsService {
    @Autowired
    private StoreOrderStatisticsMapper storeOrderStatisticsMapper;
    @Override
    public List<StoreOrder> getStoreOrder(Date startTime, Date endTime, Long deptId) {
        List<StoreOrder> result = new ArrayList<>();
        Date currentDate = new Date(startTime.getTime());
        while (!currentDate.after(endTime)) {
            // 查询当前日期的订单数量
            int orderCount = storeOrderStatisticsMapper.getOrderCountByDate(currentDate,deptId);

            // 构造OrderChange对象
            StoreOrder storeOrder = new StoreOrder();
            storeOrder.setOrderTime(currentDate);
            storeOrder.setOrderNum(orderCount);

            result.add(storeOrder);

            // 日期加1天
            currentDate = new Date(currentDate.getTime() + TimeUnit.DAYS.toMillis(1));
        }
        return result;
    }
}
